﻿<Serializable()> _
Public Class Venda

    Private getter As DelGetItens

    Private _codigo As Integer
    Public Property Codigo() As Integer
        Get
            Return _codigo
        End Get
        Set(ByVal value As Integer)
            _codigo = value
        End Set
    End Property


    Private _cliente As Cliente
    Public Property Cliente() As Cliente
        Get
            Return _cliente
        End Get
        Set(ByVal value As Cliente)
            _cliente = value
        End Set
    End Property



    Private _data As Date
    Public Property Data() As Date
        Get
            Return _data
        End Get
        Set(ByVal value As Date)
            _data = value
        End Set
    End Property



    Private _formaPagamento As FormaPagamento
    Public Property FormaPagamento() As FormaPagamento
        Get
            Return _formaPagamento
        End Get
        Set(ByVal value As FormaPagamento)
            _formaPagamento = value
        End Set
    End Property


    Private _meioVenda As MeioVenda
    Public Property MeioDeVenda() As MeioVenda
        Get
            Return _meioVenda
        End Get
        Set(ByVal value As MeioVenda)
            _meioVenda = value
        End Set
    End Property


    Private _itens As List(Of ItensVenda) = New List(Of ItensVenda)()

    Public ReadOnly Property Itens() As List(Of ItensVenda)
        Get
            If Me._codigo > 0 And Me._itens.Count = 0 Then
                Me._itens = getter.Invoke(Me._codigo)
                Return Me._itens
            Else
                Return _itens
            End If
        End Get
    End Property

    Public Delegate Function DelGetItens(ByVal codigo As Integer) As List(Of ItensVenda)

    Sub SetGetItensDelegate(ByVal getDel As DelGetItens)
        getter = getDel
    End Sub

End Class
